package com.person.android.ui.fragments;

import android.app.Activity;
import android.app.Fragment;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.media.Image;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.person.android.formatts.R;
import com.person.android.ui.activity.AboutFormatActivity;
import com.person.android.ui.activity.FeedbackActivity;
import com.person.android.widgets.FeedbackDialog;

/**
 * Created by zhaokang on 2015/11/29.
 */
public class PersonFragment extends Fragment implements View.OnClickListener {

    private View mView;
    private Context mContext;

    private ImageView mAboutImv;                    //关于按钮
    private ImageView mFeedbackImv;                 //反馈按钮
    private ImageView mNewVersionImv;               //新版本检测按钮

    private RelativeLayout mAboutContainer;         //关于按钮容器
    private RelativeLayout mFeedbackContainer;      //反馈按钮容器
    private RelativeLayout mNewVersionContainer;    //新版本检测按钮容器

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        mView = inflater.inflate(R.layout.fragment_person, container, false);
        mContext = mView.getContext();
        findViews();
        setListeners();
        return mView;
    }

    private void setListeners() {
        mAboutImv.setOnClickListener(this);
        mFeedbackImv.setOnClickListener(this);
        mNewVersionImv.setOnClickListener(this);
        mAboutContainer.setOnClickListener(this);
        mFeedbackContainer.setOnClickListener(this);
        mNewVersionContainer.setOnClickListener(this);
    }

    private void findViews() {
        mAboutImv = (ImageView) mView.findViewById(R.id.aboutGoImv);
        mFeedbackImv = (ImageView) mView.findViewById(R.id.feedbackGoImv);
        mNewVersionImv = (ImageView) mView.findViewById(R.id.versionGoImv);
        mAboutContainer = (RelativeLayout) mView.findViewById(R.id.aboutContainer);
        mFeedbackContainer = (RelativeLayout) mView.findViewById(R.id.feedbackContainer);
        mNewVersionContainer = (RelativeLayout) mView.findViewById(R.id.versionContainer);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.aboutGoImv:
            case R.id.aboutContainer:
                gotoActivity(AboutFormatActivity.class);
                break;
            case R.id.feedbackGoImv:
            case R.id.feedbackContainer:
                showFeedbackDialog();
                //gotoActivity(FeedbackActivity.class);
                break;
            case R.id.versionGoImv:
            case R.id.versionContainer:

                break;
        }
    }

    private boolean isDismiss = false;
    private void showFeedbackDialog() {
        FeedbackDialog.Builder builder = new FeedbackDialog.Builder(mContext);
        builder.setPositiveButton(R.string.feedback_dialog_button_ok, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                isDismiss = true;
                dialogInterface.dismiss();
            }
        });
        if (!isDismiss) {
            builder.create().show();
        }
        isDismiss = false;
    }

    //界面跳转
    private void gotoActivity(Class<?> cls) {
        Intent intent = new Intent(mContext, cls);
        startActivity(intent);
    }
}
